package org.yanex.project.api.parsers;

import java.io.Serializable;

import org.apache.commons.collections.map.MultiValueMap;

public class ParsedItem extends MultiValueMap implements Serializable {
	private static final long serialVersionUID = 2464402349078827554L;

	public String get(Field field, String defaultValue) {
		String s = defaultValue;
		
		if (containsKey(field)) {
			Object o = getCollection(field).iterator().next();
			if (o instanceof String)
				s=(String)o;
		}
		
		return s;
	}
	
	public double get(Field field, double defaultValue) {
		double d = defaultValue;
		
		if (containsKey(field)) {
			Object o = getCollection(field).iterator().next();
			if (o instanceof String) {
				try {
					d = Double.parseDouble((String)o);
				} catch (NumberFormatException e) {
					//default value
				}
			}
		}
		
		return d;
	}
	
	public long get(Field field, long defaultValue) {
		long l = defaultValue;
		
		if (containsKey(field)) {
			Object o = getCollection(field).iterator().next();
			if (o instanceof String) {
				try {
					l = Long.parseLong((String)o);
				} catch (NumberFormatException e) {
					//default value
				}
			}
		}
		
		return l;
	}
	
}